package com.offer;

import java.util.Stack;

public class Test30 {

    private ListNode head;

    public void push(int x) {
        if (head == null) {
            head = new ListNode(x, x);
        } else {
            ListNode listNode = new ListNode(x, Math.min(head.min, x));
            listNode.next = head;
            head = listNode;
        }
    }

    public void pop() {
        head = head.next;
    }

    public int top() {
        return head.val;
    }

    public int min() {
        return head.min;
    }

    private class ListNode {

        private int min;

        private int val;

        private ListNode next;

        public ListNode(int val, int min) {
            this.min = min;
            this.val = val;
        }
    }

    public static void main(String[] args) {
        Test30 test30 = new Test30();
//        test30.push(4);
//        test30.push(2);
//        test30.push(3);
//        test30.push(2);
        System.out.println(test30.top());
        System.out.println(test30.top());
        System.out.println(test30.top());
        System.out.println(test30.top());
        System.out.println(test30.top());
//        test30.show();
    }
}
